//
//  HttpServer.m
//  Fangmm
//
//  Created by 阮琦 on 16/3/5.
//  Copyright © 2016年 com.fangmm. All rights reserved.
//

#import "HttpServer.h"
#import "NetWorkModel.h"
#import "WechatHelpers.h"
#import "Utility.h"
#import "Constants.h"
#import "User.h"

@implementation HttpServer

NSDictionary *token()
{
    NSString *token = [Utility getObjectForKey:kToken];
    NSLog(@"token==%@",token);
    NSDictionary *headerDic = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"bearer %@",token] forKey:@"Authorization"];
    NSLog(@"yyyyy%@",token);
    return headerDic;
}

NSString *userId()
{
    NSString *userId = [Utility getObjectForKey:kUserId];
    if (userId == nil){
        userId = @"";
    }
    return userId;
}

//+ (void)getLoginWithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
//}

+ (void)getHousesWithParams:(NSDictionary *)params WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    [NetWorkModel getRequestkWithUrlString:@"/houses/app" withHttpHeader:token() withParas:params withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getHouseDetailWithHouseId:(NSString *)houseId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *stringUrl = [NSString stringWithFormat:@"/houses/%@", houseId];
    [NetWorkModel getRequestkWithUrlString:stringUrl withHttpHeader:token() withParas:@{} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getHouseTeamsWithHouseId:(NSString *)houseId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {

    NSString *stringUrl = [NSString stringWithFormat:@"/teams/houses/%@", houseId];
    [NetWorkModel getRequestkWithUrlString:stringUrl withHttpHeader:token() withParas:@{@"page":@"1", @"pageSize":@"5"} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getHouseFavoritesWithHouseId:(NSString *)houseId withParams:(NSDictionary *)params WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {

    NSString *stringUrl = [NSString stringWithFormat:@"/favorites/houses/%@", houseId];
    NSMutableDictionary *requestParams= [[NSMutableDictionary alloc]initWithObjects:@[@"1", @"5", userId()] forKeys:@[@"page", @"pageSize", @"userId"]];
    if (params == nil || params.count == 0) {
    } else {
        for (id key in [params allKeys]) {
            if ([[requestParams allKeys]containsObject:key]) {
                [requestParams setObject:[params objectForKey:key] forKey:key];
            }
        }
    }
    [NetWorkModel getRequestkWithUrlString:stringUrl withHttpHeader:token() withParas:requestParams withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)postToFavorHouseWithHouseId:(NSString *)houseId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    [NetWorkModel postRequestkWithUrlString:@"/favorites" withHeader:token() withParas:@{@"userId":userId(), @"houseId":houseId} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}
//
//+ (void)deleteFavoriteHouseWithId:(NSString *)favoriteId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
//    NSString *userId;
//    [NetWorkModel deleteRequestkWithUrlString:@"" withHeader:<#(NSDictionary *)#> withParas:<#(NSDictionary *)#> withSuccessBlock:<#^(NSDictionary *)successblock#> withFailBlock:<#^(id)failBlock#>]
//}
#pragma mark - 小区详情
+(void)getCommunityWithCommunityID:(NSString*)communityID withSuccessBlock:(void (^)(NSDictionary*))successBlock withFailBlock:(void(^)(id))failBlock
{
    NSString *urlSting = [NSString stringWithFormat:@"/communities/%@",communityID];
    [NetWorkModel getRequestkWithUrlString:urlSting withHttpHeader:token() withParas:@{} withSuccessBlock:^(NSDictionary *responseData)
    {
        successBlock(responseData);
    }
    withFailBlock:^(id failMessage)
    {
        failBlock(failMessage);
    }];
}
#pragma mark - 周边小区
+(void)getSourroundingCommunityWithCommunityID:(NSString *)communityID withSuccessBlock:(void(^)(NSDictionary*))successBlock withFailBlock:(void(^)(id))failBlock
{
    NSString *urlString = [NSString stringWithFormat:@"/communities/%@/surroundings",communityID];
    [NetWorkModel getRequestkWithUrlString:urlString withHttpHeader:token() withParas:@{} withSuccessBlock:^(NSDictionary *respondData)
    {
        successBlock(respondData);
    }
    withFailBlock:^(id failMessage)
    {
        failBlock(failMessage);
    }];
}

+ (void)deleteFavoriteHouseWithId:(NSString *)favoriteId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *requestUrl = [NSString stringWithFormat:@"/favorites/%@",favoriteId];
    [NetWorkModel deleteRequestkWithUrlString:requestUrl withHeader:token() withParas:nil withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getUserFavoritesWithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *requestUrl = [NSString stringWithFormat:@"favorites/users/%@",userId()];
    [NetWorkModel getRequestkWithUrlString:requestUrl withHttpHeader:token() withParas:@{} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getUserRequirementsWithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    [NetWorkModel getRequestkWithUrlString:@"/requirements/lastest"withHttpHeader:token() withParas:@{@"userId":userId()} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getRequirementsStatistics:(Requirement *)requirement WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    [NetWorkModel getRequestkWithUrlString:@"/statistics/requirement" withHttpHeader:token() withParas:@{@"rent":[NSString stringWithFormat:@"%@",requirement.price], @"day":[NSString stringWithFormat:@"%d",requirement.day], @"regionCode":[NSString stringWithFormat:@"%d",requirement.regionCode] } withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getFocusedHousesSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *requestUrl = [NSString stringWithFormat:@"/favorites/users/%@",userId()];
    [NetWorkModel getRequestkWithUrlString:requestUrl withHttpHeader:token() withParas:@{@"page":@"1", @"pageSize":@"10"} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getOpenAreaWithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *cityCode = [Utility getObjectForKey:kCityCode];
    if (cityCode == nil) {
        cityCode = @"3502";
    }
    NSString *requestUrl = [NSString stringWithFormat:@"/settings/cities/%@",cityCode];
    [NetWorkModel getRequestkWithUrlString:requestUrl withHttpHeader:token() withParas:@{} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

#pragma mark - 用户小组列表
+(void)getRoomMateTeamWithUserId:(NSString*)userID withPage:(int)page withPageSize:(int)pageSize withSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock
{
    NSString *urlString = [NSString stringWithFormat:@"/teams/users/%@",userID];
    [NetWorkModel getRequestkWithUrlString:urlString withHttpHeader:token() withParas:@{@"pageSize":[NSNumber numberWithInt:pageSize],@"page":[NSNumber numberWithInt:page]} withSuccessBlock:^(NSDictionary *responseData)
    {
        successBlock(responseData);
    }
    withFailBlock:^(id errorMessage)
    {
        errorBlock(errorMessage);
    }];
}
#pragma mark - 发布房源
+(void)PostHouseWithHouse:(House*)house WithSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))failBlock
{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:house.comment forKey:@"comment"];
    [dic setValue:house.rentTime forKey:@"rentTime"];
    [dic setValue:[NSNumber numberWithInt:house.rent] forKey:@"rent"];
    [dic setValue:[NSNumber numberWithInt:house.toiletNum] forKey:@"toiletNum"];
    [dic setValue:[NSNumber numberWithInt:house.hallNum] forKey:@"hallNum"];
    [dic setValue:[NSNumber numberWithInt:house.roomNum] forKey:@"roomNum"];
    [dic setValue:house.community forKey:@"community"];
    [dic setValue:house.fileIds forKey:@"fileIds"];
    [dic setValue:house.userId forKey:@"userId"];
    [dic setValue:[NSNumber numberWithInt:house.cityCode] forKey:@"cityCode"];
    [NetWorkModel postRequestkWithUrlString:@"/houses" withHeader:token() withParas:dic withSuccessBlock:^(NSDictionary *responseData)
    {
        successBlock(responseData);
    } withFailBlock:^(id errorMessage)
    {
        failBlock(errorMessage);
    }];
}
#pragma mark - 小组行程
+(void)getScheduleWithSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))failedBlock
{
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:[Utility getObjectForKey:kUserId] forKey:@"userId"];
    [NetWorkModel getRequestkWithUrlString:@"/schedules/latest" withHttpHeader:token() withParas:dic withSuccessBlock:^(NSDictionary *responseData)
    {
        successBlock(responseData);
    }
    withFailBlock:^(id data)
    {
        failedBlock(data);
    }];
}
#pragma mark - 上传图片

+ (void)postToJoinTeam:(NSString *)teamId WithSeatId:(NSString *)seatId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *requestUrl = [NSString stringWithFormat:@"/teams/%@/applications",teamId];
    [NetWorkModel postRequestkWithUrlString:requestUrl withHeader:token() withParas:@{@"userId":userId(), @"seatId":seatId} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getPersonDetailWithId:(NSString *)Id WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *userIdString;
    if (Id) {
        userIdString = Id;
    } else {
        userIdString = userId();
    }
    NSString *requestUrl = [NSString stringWithFormat:@"/users/%@",userIdString];
    [NetWorkModel getRequestkWithUrlString:requestUrl withHttpHeader:token() withParas:@{} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)postAvatarImageWith:(NSData *)imageData WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    [NetWorkModel upLoadFileWithData:imageData withName:@"file" toURL:@"/images/avatars/users" withParas:@{@"userId":userId()} withHeader:token() withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)putUserInfoWithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *requestUrl = [NSString stringWithFormat:@"/users/%@",userId()];
    User *user = [User sharedUser];
    NSMutableDictionary *userParams = [[NSMutableDictionary alloc]init];
    if (user.name != nil && ![user.name isEqual:@"未完善"]) {
        [userParams setObject:user.name forKey:@"name"];
    }
    if (user.gender != nil && ![user.gender isEqual:@"未完善"]) {
        [userParams setObject:user.gender forKey:@"gender"];
    }
    if (user.constellation != nil && ![user.constellation isEqual:@"未完善"]) {
        [userParams setObject:user.constellation forKey:@"constellation"];
    }
    [userParams setObject:[NSString stringWithFormat:@"%d",user.ageGroup] forKey:@"ageGroup"];
    if (user.country != nil && ![user.country isEqual:@"未完善"]) {
        [userParams setObject:user.country forKey:@"country"];
    }
    if (user.province != nil && ![user.province isEqual:@"未完善"]) {
        [userParams setObject:user.province forKey:@"province"];
    }
    if (user.city != nil && ![user.city isEqual:@"未完善"]) {
        [userParams setObject:user.city forKey:@"city"];
    }
    if (user.industry != nil && ![user.industry isEqual:@"未完善"]) {
        [userParams setObject:user.industry forKey:@"industry"];
    }
    if (user.company != nil && ![user.company isEqual:@"未完善"]) {
        [userParams setObject:user.company forKey:@"company"];
    }
    if (user.profession != nil && ![user.profession isEqual:@"未完善"]) {
        [userParams setObject:user.profession forKey:@"profession"];
    }
    if (user.identityCard != nil && ![user.identityCard isEqual:@"未完善"]) {
        [userParams setObject:user.fullName forKey:@"fullName"];
    }
    if (user.fullName != nil && ![user.fullName isEqual:@"未完善"]) {
        [userParams setObject:user.identityCard forKey:@"identityCard"];
    }
    if (user.companyMail != nil && ![user.companyMail isEqual:@"未完善"]) {
        [userParams setObject:user.companyMail forKey:@"companyMail"];
    }
    if (user.tags != nil && user.tags.count != 0) {
        NSString *tagString;
        for (NSString *string in user.tags) {
            if ([user.tags.firstObject isEqualToString:string]) {
                tagString = string;
            } else {
                tagString = [NSString stringWithFormat:@"%@,%@",tagString, string];
            }
        }
        [userParams setObject:tagString forKey:@"tags"];
    }
    [userParams setObject:userId() forKey:@"userId"];
    [NetWorkModel putRequestkWithUrlString:requestUrl withHeader:token() withParas:userParams withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failDic) {
        failBlock(failDic);
    }];
}

+ (void)postToGetVcodeWithMobile:(NSString *)mobile WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    [NetWorkModel postRequestkWithUrlString:@"/sms/user/register" withHeader:token() withParas:@{@"mobile":mobile} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getRoomMateTeamWithUserId:(NSString*)userId withStatus:(NSString *)status withPage:(int)page withPageSize:(int)pageSize withUserInfo:(NSDictionary *)userInfo withSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock
{
    NSString *urlString = [NSString stringWithFormat:@"/teams/users/%@",userId];
    NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
    [paraDic setValue:status forKey:@"status"];
    [paraDic setValue:[NSNumber numberWithInt:pageSize] forKey:@"pageSize"];
    [paraDic setValue:[NSNumber numberWithInt:page] forKey:@"page"];
    [paraDic addEntriesFromDictionary:userInfo];
    [NetWorkModel getRequestkWithUrlString:urlString withHttpHeader:token() withParas:paraDic withSuccessBlock:^(NSDictionary *responseData)
     {
         successBlock(responseData);
     }
        withFailBlock:^(id errorMessage)
     {
         errorBlock(errorMessage);
     }];
}

+ (void)getTeamTipsWithHouseId:(NSString *)houseId withSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock
{
    NSString *urlString = [NSString stringWithFormat:@"/teams/tips"];
    [NetWorkModel getRequestkWithUrlString:urlString withHttpHeader:token() withParas:@{@"userId":userId(), @"houseId":houseId} withSuccessBlock:^(NSDictionary *responseData)
     {
         successBlock(responseData);
     }
        withFailBlock:^(id errorMessage)
     {
         errorBlock(errorMessage);
     }];
}

+(void)upLoadHousePhotoWithDataArray:(NSArray*)dataArray withSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock
{
    [NetWorkModel uploadMutableDataWithUrlString:@"/images/houses" withParas:@{} withHeaderDic:token() withFileName:@"files" withName:@"files" WithDataArray:dataArray withSuccessBlock:^(NSDictionary *responseData)
    {
        successBlock(responseData);
    } withFailBlock:^(id errorMsg)
    {
        errorBlock(errorMsg);
    }];
}
#pragma mark - 小组的申请列表
+(void)getApplicationListWithTeamId:(NSString *)teamId withPage:(int)page withPageSize:(int)pageSize withSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock
{
    NSString *urlString = [NSString stringWithFormat:@"/teams/%@/applications",teamId];
    [NetWorkModel getRequestkWithUrlString:urlString withHttpHeader:token() withParas:@{@"page":[NSNumber numberWithInt:page],@"pageSize":[NSNumber numberWithInt:pageSize]} withSuccessBlock:^(NSDictionary *responseData)
    {
        successBlock(responseData);
    } withFailBlock:^(id errorMsg)
    {
        errorBlock(errorMsg);
    }];
}
#pragma mark - 接受申请
+(void)passApplyWithTeamId:(NSString *)teamId WithApply:(NSString *)applyId withSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock
{
    NSString *urlString = [NSString stringWithFormat:@"/teams/%@/applications/%@",teamId,applyId];
    [NetWorkModel putRequestkWithUrlString:urlString withHeader:token() withParas:@{@"status":@"pass"} withSuccessBlock:^(NSDictionary *responseData)
    {
        successBlock(responseData);
    } withFailBlock:^(id errorMsg)
    {
        errorBlock(errorMsg);
    }];
}
#pragma mark - 拒接申请
+(void)rejectApplyWithTeamId:(NSString *)teamId WithApply:(NSString *)applyId withSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock
{
    NSString *urlString = [NSString stringWithFormat:@"/teams/%@/applications/%@",teamId,applyId];
    [NetWorkModel putRequestkWithUrlString:urlString withHeader:token() withParas:@{@"status":@"reject"} withSuccessBlock:^(NSDictionary *responseData)
     {
         successBlock(responseData);
     } withFailBlock:^(id errorMsg)
     {
         errorBlock(errorMsg);
     }];
}

+ (void)getWXcodeWithCode:(NSString *)code WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *requestUrl = [NSString stringWithFormat:@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx6fb1728f4cd25c6e&secret=8ed73fdad657de80f257204e67deddbf&code=%@&grant_type=authorization_code",code];
    [WechatHelpers getWXAccessTokenRequestkWithUrlString:requestUrl withHttpHeader:nil withParas:nil withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        NSLog(@"%@",failData);
    }];
}

+ (void)getWXUserWithOpenId:(NSString *)openId andAccessToken:(NSString *)accessToken WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *openIdString;
    NSString *accessTokenString;
    if (openId == nil) {
        openIdString = [Utility getObjectForKey:kWXOpenId];
    } else {
        openIdString = openId;
    }
    if (accessToken == nil) {
        accessTokenString = [Utility getObjectForKey:kWXAccessToken];
    } else {
        accessTokenString = accessToken;
    }
    NSString *requestUrl = [NSString stringWithFormat:@"https://api.weixin.qq.com/sns/userinfo?access_token=%@&openid=%@",accessTokenString, openIdString];
    [WechatHelpers getWXUserInfoRequestkWithUrlString:requestUrl withHttpHeader:nil withParas:@{@"lang":@"zh_CN"} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)postToAuthLoginWithOpenId:(NSString *)openId andAccessToken:(NSString *)accessToken WithWechatUserData:(id)user WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock; {
    NSString *name = [user objectForKey:@"nickname"];
    NSString *avatar = [user objectForKey:@"headimgurl"];
    NSString *sex = [NSString stringWithFormat:@"%@",[user objectForKey:@"sex"]];
    NSString *gender;
    if ([sex isEqualToString:@"1"]) {
        gender = @"m";
    } else {
        gender = @"f";
    }
    NSString *country = [user objectForKey:@"country"];
    NSString *province = [user objectForKey:@"province"];
    NSString *city = [user objectForKey:@"city"];
    
    [NetWorkModel postRequestkWithUrlString:@"/users" withHeader:nil withParas:@{@"openid":openId, @"oauth":@"wx_app", @"accessToken":accessToken, @"name":name, @"avatar":avatar, @"gender":gender, @"country":country, @"province":province, @"city":city} withSuccessBlock:^(NSDictionary * successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)postToGetNewRegisterVcodeWithMobile:(NSString *)mobile WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    [NetWorkModel postRequestkWithUrlString:@"/sms/user/register" withHeader:token() withParas:@{@"mobile":mobile} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)postToLoginWithMobile:(NSString *)mobile Vcode:(NSString *)vcode AndOauthId:(NSString *)oauthId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    [NetWorkModel postRequestkWithUrlString:@"/users" withHeader:nil withParas:@{@"mobile":mobile, @"vcode":vcode, @"oauthId":oauthId} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)postToSubmitRequirementWithParas:(NSDictionary *)params WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSMutableDictionary *paramsDic = [[NSMutableDictionary alloc]initWithDictionary:params];
    [paramsDic setObject:[Utility getObjectForKey:kUserId] forKey:@"userId"];
    [NetWorkModel postRequestkWithUrlString:@"/requirements" withHeader:token() withParas:paramsDic withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)putRequirementWithParas:(NSDictionary *)params WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSMutableDictionary *paramsDic = [[NSMutableDictionary alloc]initWithDictionary:params];
    Requirement *requirement = [Utility getObjectForKey:kRequirement];
    NSString *requestUrl = [NSString stringWithFormat:@"/requirements/%@",requirement.requirementId];
    [NetWorkModel putRequestkWithUrlString:requestUrl withHeader:token() withParas:paramsDic withSuccessBlock:^(NSDictionary * successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}


+ (void)postToCreateTeamWithHouseId:(NSString *)houseId AndOffers:(NSString *)offers WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    [NetWorkModel postRequestkWithUrlString:@"/teams" withHeader:token() withParas:@{@"houseId":houseId, @"userId":userId(), @"offers":offers} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);

    }];
}

+ (void)getTeamWithId:(NSString *)teamId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *requestUrl = [NSString stringWithFormat:@"/teams/%@",teamId];
    [NetWorkModel getRequestkWithUrlString:requestUrl withHttpHeader:token() withParas:@{} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getAdsWithType:(NSString *)type WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *cityCode = [Utility getObjectForKey:kCityCode];
    if (cityCode == nil) {
        cityCode = @"3502";
    }
    [NetWorkModel getRequestkWithUrlString:@"/cms/ads" withHttpHeader:token() withParas:@{@"classify":type, @"cityCode":[NSString stringWithFormat:@"%@",cityCode]} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

#pragma mark - 账户接口
+(void)getAccountMssageWithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    [NetWorkModel getRequestkWithUrlString:@"/payments/accounts" withHttpHeader:token() withParas:@{@"userId":userId()} withSuccessBlock:^(NSDictionary *responseData)
    {
        successblock(responseData);
    }
    withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}
#pragma mark - 设置支付密码
+(void)setPayKeyWithKey:(NSString *)key WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    [NetWorkModel postRequestkWithUrlString:@"/payments/accounts" withHeader:token() withParas:@{@"userId":[Utility getObjectForKey:kUserId],@"password":key} withSuccessBlock:^(NSDictionary *responseData)
    {
        successblock(responseData);
    }
     withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}
#pragma mark - 提现申请
+(void)applyDrawCashWithMoney:(NSInteger)money withPassword:(NSString*)password WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    NSMutableDictionary *paraDic = [NSMutableDictionary dictionary];
    [paraDic setObject:[Utility getObjectForKey:kUserId] forKey:@"userId"];
    [paraDic setValue:password forKey:@"password"];
    [paraDic setObject:[NSNumber numberWithInteger:money] forKey:@"money"];
    [NetWorkModel postRequestkWithUrlString:@"/payments/withdrawals" withHeader:token() withParas:paraDic withSuccessBlock:^(NSDictionary *responseData)
    {
        successblock(responseData);
    }
    withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}
#pragma mark - 充值
+(void)inpoursWithMoney:(NSInteger)money WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    [NetWorkModel postRequestkWithUrlString:@"/payments/inpours" withHeader:token() withParas:@{@"money":[NSNumber numberWithInteger:money],@"userId":[Utility getObjectForKey:kUserId]} withSuccessBlock:^(NSDictionary *responseData)
    {
        successblock(responseData);
    } withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}
#pragma mark - 意向金消费
+(void)payEarnestWithMoney:(int)money withScheduleId:(NSString *)scheduleId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    [NetWorkModel postRequestkWithUrlString:@"/payments/earnests" withHeader:token() withParas:@{@"userId":[Utility getObjectForKey:kUserId],@"money":[NSNumber numberWithInteger:money],@"scheduleId":scheduleId} withSuccessBlock:^(NSDictionary *responseData)
    {
        successblock(responseData);
    } withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}
#pragma mark - 保证金消费
+(void)payTrusteesWithSchedule:(NSString*)scheduleId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    [NetWorkModel postRequestkWithUrlString:@"/payments/trustees" withHeader:token() withParas:@{@"userId":[Utility getObjectForKey:kUserId],@"scheduleId":scheduleId} withSuccessBlock:^(NSDictionary *responseData)
     {
         successblock(responseData);
     }
    withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}


+(void)getBalanceWithSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock {

    [NetWorkModel getRequestkWithUrlString:@"/payments/accounts" withHttpHeader:token() withParas:@{@"userId":userId()} withSuccessBlock:^(NSDictionary *responseData)
     {
         successBlock(responseData);
     } withFailBlock:^(id errorMsg)
     {
         errorBlock(errorMsg);
     }];
}


+ (void)postToLoginWithMobile:(NSString *)mobile Vcode:(NSString *)vcode  WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock {
    NSString *requestUrl = [NSString stringWithFormat:@"/users/%@",userId()];
    [NetWorkModel postRequestkWithUrlString:requestUrl withHeader:nil withParas:@{@"mobile":mobile, @"vcode":vcode} withSuccessBlock:^(NSDictionary *successDic) {
        successblock(successDic);
    } withFailBlock:^(id failData) {
        failBlock(failData);
    }];
}

+ (void)getSharelinksWithType:(NSString *)type sharedInfo:(NSString *)sharedInfo WithSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock {
    NSDictionary *generalParams = @{@"userId":userId(), @"type":type};
    NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:generalParams];
    [params setObject:sharedInfo forKey:@"shareId"];
    [NetWorkModel getRequestkWithUrlString:@"/sharelinks" withHttpHeader:token() withParas:params withSuccessBlock:^(NSDictionary *responseData)
     {
         successBlock(responseData);
     } withFailBlock:^(id errorMsg)
     {
         errorBlock(errorMsg);
     }];
}

+ (void)getRecommendWithSuccessBlock:(void(^)(NSDictionary*))successBlock withFailedBlock:(void(^)(id))errorBlock {
    NSDictionary *generalParams = @{@"userId":userId()};
    NSMutableDictionary *params = [[NSMutableDictionary alloc]initWithDictionary:generalParams];
    [NetWorkModel getRequestkWithUrlString:@"/recommends" withHttpHeader:token() withParas:params withSuccessBlock:^(NSDictionary *responseData)
     {
         successBlock(responseData);
     } withFailBlock:^(id errorMsg)
     {
         errorBlock(errorMsg);
     }];
}
#pragma mark  - 阿里wap支付
+(void)aliWapPayWithOutTradeNo:(NSString *)outTradeNo WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    [NetWorkModel getRequestkWithUrlString:@"/tradewap/alipay" withHttpHeader:token() withParas:@{@"outTradeNo":outTradeNo} withSuccessBlock:^(id responseData)
    {
        successblock(responseData);
    }
    withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}
#pragma mark - 获取保证金
+(void)getTrusteesWithScheduleId:(NSString *)scheduleId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    [NetWorkModel getRequestkWithUrlString:@"/payments/trustees" withHttpHeader:token() withParas:@{@"scheduleId":scheduleId,@"userId":[Utility getObjectForKey:kUserId]} withSuccessBlock:^(NSDictionary *responseData)
    {
        successblock(responseData);
    }
    withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}
#pragma mark - 获取意向金
+(void)getEarnestsWithScheduleId:(NSString *)scheduleId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    [NetWorkModel getRequestkWithUrlString:@"/payments/earnests" withHttpHeader:token() withParas:@{@"scheduleId":scheduleId,@"userId":[Utility getObjectForKey:kUserId]} withSuccessBlock:^(NSDictionary *responseData)
    {
        successblock(responseData);
    }
    withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}

#pragma 寝室申请状态
+(void)getApplyStateWithUserId:(NSString *)userId WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failBlock
{
    [NetWorkModel getRequestkWithUrlString:@"/teams/applications" withHttpHeader:token() withParas:@{@"userId":userId,@"excludes":@"user"} withSuccessBlock:^(NSDictionary *responseData)
    {
        successblock(responseData);
    }
    withFailBlock:^(id errorMsg)
    {
        failBlock(errorMsg);
    }];
}


#pragma mark - Configuring the view’s layout behavior
+ (void)getPoisWithKeyword:(NSString *)keyword WithSuccessBlock:(void(^)(NSDictionary*))successblock withFailBlock:(void(^)(id))failblock {
    NSString *requestUrl = [NSString stringWithFormat:@"/pois/%@",keyword];
    NSString *cityCode = [Utility getObjectForKey:kCityCode];
    [NetWorkModel getRequestkWithUrlString:requestUrl withHttpHeader:token() withParas:@{@"cityCode":cityCode} withSuccessBlock:^(NSDictionary *responseData) {
        successblock(responseData);
    } withFailBlock:^(id errorMsg) {
        failblock(errorMsg);
    }];
}

@end
